//
//  NSDictionary+PLvalue.m
//  PlatformCommon
//
//  Created by KimmanYip on 2017/9/26.
//
//

#import "NSDictionary+PLDefaultValue.h"

@implementation NSDictionary(PLvalue)

- (BOOL)pl_boolForKey:(NSString *)key defaultValue:(BOOL)value {
    id obj = [self objectForKey:key];
    return obj == nil ? value : [obj boolValue];
}

- (int)pl_intForKey:(NSString *)key defaultValue:(int)value {
    id obj = [self objectForKey:key];
    return obj == nil ? value : [obj intValue];
}

- (long long)pl_longLongForKey:(NSString *)key defaultValue:(long long)value {
    id obj = [self objectForKey:key];
    return obj == nil ? value : [obj longLongValue];
}

- (NSString *)pl_stringForKey:(NSString *)key defaultValue:(NSString *)value {
    id obj = [self objectForKey:key];
    if ([obj isKindOfClass:NSString.class]) {
        return obj ?: value;
    }
    return obj == nil ? value : [obj stringValue];
}

@end
